package com.yunpeng.dishes.dao.model;

import java.io.Serializable;
import java.util.Date;

/**
 * BaseDO 基础字段表
 *
 * @author : Moore(hemw)
 * @date : 2020-03-26
 */
public abstract class BaseDO implements Serializable {

    /**
     * 自增记录id
     */
    protected Long id;
    /**
     * 数据标志位，默认为1
     * 1 正常使用
     * 0 逻辑删除
     */
    protected Short flag;
    /**
     * 创建人
     */
    protected Long creator;
    /**
     * 创建时间
     */
    protected Date createTime;
    /**
     * 更新人
     */
    protected Long updater;
    /**
     * 更新时间
     */
    protected Date updateTime;

    public BaseDO() {
        flag = 1;
    }

    public BaseDO(Long id, Short flag, Long creator, Date createTime, Long updater, Date updateTime) {
        this.id = id;
        this.flag = 1;
        this.creator = creator;
        this.createTime = createTime;
        this.updater = updater;
        this.updateTime = updateTime;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Short getFlag() {
        if (flag == null) {
            flag = 1;
        }
        return flag;
    }

    public void setFlag(Short flag) {
        this.flag = flag;
    }

    public Long getCreator() {
        return creator;
    }

    public void setCreator(Long creator) {
        this.creator = creator;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Long getUpdater() {
        return updater;
    }

    public void setUpdater(Long updater) {
        this.updater = updater;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public String toString() {
        return "BaseDO{" +
                "id=" + id +
                ", flag=" + flag +
                ", creator='" + creator + '\'' +
                ", createTime=" + createTime +
                ", updater='" + updater + '\'' +
                ", updateTime=" + updateTime +
                '}';
    }

    public void initForNew(Long userId) {
        this.flag = 1;
        this.creator = userId;
        this.updater = userId;
        Date now = new Date();
        this.createTime = now;
        this.updateTime = now;
    }

}
